package com.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.demo.common.utils.compare.CompareConvertName;
import com.demo.common.utils.compare.FieldCompare;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.demo.common.excel.ExcelField;
import lombok.Data;

import java.time.LocalDateTime;

import static com.demo.common.excel.ExcelConvertName.LOCAL_DATE_TIME_SERIALIZABLE;
import static com.demo.common.excel.ExcelConvertName.ROLE_ID_TO_NAME;
import static com.demo.common.excel.ExcelConvertName.ROLE_NAME_TO_ID;

@Data
@TableName("sys_user")
public class SysUser {

    @ExcelField(useImport = false,name = "用户id")
    @TableId(type=IdType.AUTO)
    private Integer id;

    @ExcelField(name = "手机号")
    private String mobile;
    /**
     * 密码，返回数据里不返回该字段
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String pwd;

    @ExcelField(name = "角色",importConvert = ROLE_NAME_TO_ID,exportConvert = ROLE_ID_TO_NAME)
    @FieldCompare(name = "角色",showConvert = CompareConvertName.SHOW_SYS_ROLE_NAME)
    private Integer roleId;

    /**
     * 0-正常 1-注销
     */
    @ExcelField(name = "状态",simpleConvert = "0=正常,1=注销",useImport = false)
    @FieldCompare(name="状态",showConvert = CompareConvertName.SHOW_SYS_STATUS)
    private Integer status;

    @ExcelField(name = "创建时间",exportConvert = LOCAL_DATE_TIME_SERIALIZABLE,useImport = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

    /**
     * 头像
     */
    private String headImg;

    public static final String ROLE_ID="role_id";

    public static final String ID="id";

    public static final String MOBILE="mobile";

    public static final String STATUS="status";

    public static final String CREATE_TIME="create_time";

}
